package org.wattdepot.cli.command;

import java.util.List;
import org.wattdepot.cli.CommandLineInterface;

/**
 * Prints a list of all commands and their explanations.
 * 
 * @author BJ Peter DeLaCruz, Wahib Hanani, Lyneth Peou
 * @version 2.0
 */
public class Help extends CliCommandInterface {

  /** Carriage return on this operating system. */
  private static final String CARRIAGE_RETURN = System.getProperty("line.separator");

  /**
   * Carries out the command inputted by the user on the command prompt.
   * 
   * @param cli A CommandLineInterface object.
   * @param commandList Command inputted by the user on the command prompt.
   * @return Result after running the command.
   */
  public String doCommand(CommandLineInterface cli, List<String> commandList) {
    return getHelp();
  }

  /**
   * Prints a list of all commands and their explanations.
   * 
   * @return Information about all of the commands available on this system.
   */
  private final String getHelp() {
    StringBuffer buffer = new StringBuffer(2500);
    buffer.append("> help" + CARRIAGE_RETURN + "  This message."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> quit" + CARRIAGE_RETURN + "  Exits the system."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> sources" + CARRIAGE_RETURN
        + "  Prints a table summarizing all of the public power sources available on"
        + " this server, one per line."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> summary {source}" + CARRIAGE_RETURN
        + "  Prints information about a single power source."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> sensordata {source} timestamp {timestamp}" + CARRIAGE_RETURN
        + "  Prints information about a single sensor data instance."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> dailysensordata {source} day {day}" + CARRIAGE_RETURN
        + "  Prints a table listing all of the sensor data instances for the specified day."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> power [generated|consumed] {source} timestamp {timestamp}" + CARRIAGE_RETURN
        + "  Prints the power generated or consumed by a power source at the given timestamp."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> powerstats [generated|consumed] {source} day {day} sampling-interval"
        + " {minutes} statistic {max|min|average}" + CARRIAGE_RETURN
        + "  Returns the maximum, minimum, or average power generated or consumed by the power"
        + " source for the given day."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> total [carbon|energy] [generated|consumed] {source} day {day} sampling-interval"
        + " {minutes}"
        + CARRIAGE_RETURN
        + "  Returns the total amount of carbon or energy generated (or energy consumed) by this"
        + " power source for the given day."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> chart power [generated|consumed] {source} {startday} {endday} sampling-interval"
        + " {minutes} file {file}" + CARRIAGE_RETURN
        + "  Generates an HTML file that will display a chart illustrating the power"
        + " generated or consumed for the power source over the given interval."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> fueltypes {source}" + CARRIAGE_RETURN
        + "  Generates a table where the first column contains fuel types and the second column is"
        + " a comma-delimited list of non-virtual power sources that use that fuel type."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> totalpower {source} {timestamp} fueltype {fueltype}" + CARRIAGE_RETURN
        + "  Returns the total power generated by all non-virtual power sources that use the"
        + " specified fuel type and are associated with the specified power source."
        + CARRIAGE_RETURN + CARRIAGE_RETURN
        + "> carboncontent {source} {timestamp} sampling-interval {interval}" + CARRIAGE_RETURN
        + "  Computes the carbon content of a power source (units are lbs CO2 / MWh)."
        + CARRIAGE_RETURN + CARRIAGE_RETURN);

    return buffer.toString();
  }

}